<template>
	<div>
		<el-row :gutter="10">
			<el-col :span="24">
				<el-card shadow="never" class="card">
					<div id="charts_one" style="width:100%;min-height:80vh">
						<Search size='small' :searchVisible="searchVisible" :searchData.sync="searchData"  :searchForm="searchForm" @refresh_list="index"></Search>
						<div class="btn-group" style="margin-bottom:11px;">
                           <div>

                 <el-button type="info"  size="mini" icon="el-icon-view"  @click="importUpdateData(ids)">导入变更单</el-button>
                 <el-button type="warning"  size="mini" icon="el-icon-upload"  @click="importData(ids)">{{$t('action.importData')}}</el-button>
             </div>
             <table-tool :searchVisible.sync="searchVisible"  :fieldList="fieldList" @refresh_list="index" :searchTool="true"></table-tool>
						</div>
					    <el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="Id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">		   
						    <el-table-column align="center" type="selection" width="42"></el-table-column>
							<el-table-column align="center" type='' v-if="fieldList[0].checked" property="Id" label="ID" show-overflow-tooltip width="70">
							</el-table-column>
                <el-table-column align="center"  v-if="fieldList[6].checked" property="syncNo" :label="$t('field.SaleOrder_SyncNo')" show-overflow-tooltip width="" >
                </el-table-column>
							<el-table-column align="center"  v-if="fieldList[1].checked" property="cusTomer" :label="$t('field.SaleOrder_CusTomer')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[2].checked" property="cusBillNo" :label="$t('field.SaleOrder_CusBillNo')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[3].checked" property="inDate" :label="$t('field.SaleOrder_InDate')" show-overflow-tooltip width="" >
							</el-table-column>
                <el-table-column align="center"  v-if="fieldList[5].checked" property="weekNo" :label="$t('field.SaleOrder_WeekNo')" show-overflow-tooltip width="" >
                </el-table-column>
<!--							<el-table-column align="center"  v-if="fieldList[4].checked" property="user" :label="$t('field.SaleOrder_User')" show-overflow-tooltip width="" >-->
<!--							</el-table-column>-->

                <el-table-column :fixed="$store.getters.device !== 'mobile'?'right':false" :label="$t('system.operation')" align="center" width="160">
                  <template slot-scope="scope">
                    <div v-if="scope.row.id">
                      <el-button size="mini" type="text" @click="detail(scope.row)"  style="color:#0066FF" ><i class="el-icon-view" />{{$t('action.detail')}}</el-button>
                      <el-button size="mini" type="text" @click="del(scope.row)"  style="color:#FF0000" ><i class="el-icon-view" />删除</el-button>
                    </div>
                  </template>
                </el-table-column>
						</el-table>
						<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
					</div>
				</el-card>
			</el-col>
		</el-row>

		<!--查看详情-->
		<Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refresh_list="index"></Detail>
	    <!--导入-->
		<ImportData  :show.sync="dialog.importDataDialogStatus" size="small" @refresh_list="index"></ImportData>

    <!--导入变更单-->
    <UpdateData  :show.sync="dialog.updateDataDialogStatus" size="small" @refresh_list="index"></UpdateData>
	</div>
</template>
<script>
	import {
	    index, 
	    updateExt, 
	    getUpdateInfo,
	    del,
	} from '@/api/app/saleorder'
	import Search from '@/components/common/Search.vue'
	import Page from '@/components/common/Page.vue'
	import TableTool from '@/components/common/TableTool.vue'
	import { confirm,param2Obj } from '@/utils/common'
	import Add from '@/views/app/saleorder/add.vue' 
	import Update from '@/views/app/saleorder/update.vue' 
	import Detail from '@/views/app/saleorder/detail.vue' 
	import ImportData from '@/views/app/saleorder/importData.vue' 
	import UpdateData from '@/views/app/saleorder/importUpdateData.vue'
	export default {
		name:'saleOrder',
		components: {
			Search,
			Page,
			TableTool,
	        Add,  
	        Update,  
	        Detail,  
	        ImportData,
      UpdateData
		},
		data(){
			return {
				dialog: {
	                    addDialogStatus : false,           
	                    updateDialogStatus : false,           
	                    detailDialogStatus : false,           
	                    importDataDialogStatus : false,           
	                    updateDataDialogStatus : false,
				},
				fieldList:[
					{lable:'ID',checked:false},
				    {lable:this.$t('field.SaleOrder_CusTomer'),checked:true},
				    {lable:this.$t('field.SaleOrder_CusBillNo'),checked:true},
				    {lable:this.$t('field.SaleOrder_InDate'),checked:true},
				    {lable:this.$t('field.SaleOrder_WeekNo'),checked:true},
				    {lable:this.$t('field.SaleOrder_User'),checked:true},
          {lable:this.$t('field.SaleOrder_SyncNo'),checked:true}
				],
				ids: [],
				selectRows:[],
				selectTotal:0,
				single:true,
				multiple:true,
				list: [],
				small_tables:{},
	            addInfo:{},
	            updateInfo:{},
	            detailInfo:{},
	            importDataInfo:{},
				loading: false,
				page_data: {
					limit: 20,
					page: 1,
					total:20,
				},
				searchVisible:true,
				searchForm:[],
				searchData:{},
			}
		},
		methods: {
			index(){
				let param = {limit:this.page_data.limit,page:this.page_data.page}
				Object.assign(param, this.searchData,param2Obj(this.$route.fullPath))
				this.loading = true
				index(param).then(res => {
					this.list = res.data.data
					this.small_tables=res.sql_field_data
					this.page_data.total = res.data.total
					this.loading = false
					if(this.page_data.page == 1){
						this.searchForm = [
						        {type:'Input',label:this.$t('field.SaleOrder_CusTomer'),prop:'cusTomer',width:'150px'},
						        {type:'Input',label:this.$t('field.SaleOrder_CusBillNo'),prop:'cusBillNo',width:'150px'},
						        {type:'Input',label:this.$t('field.SaleOrder_SyncNo'),prop:'syncNo',width:'150px'},
						        {type:'datetime',label:this.$t('field.SaleOrder_InDate'),prop:'inDate',width:'150px'},
						        {type:'Input',label:this.$t('field.SaleOrder_User'),prop:'user',width:'150px'},
						]
					}
				})
			},
			updateExt(row,field){
				if(row.Id){
					updateExt({Id:row.Id,[field]:row[field]}).then(res => {
						this.$message({message: this.$t('system.success'), type: 'success'})
					})
				}
			},
			add(){
				this.dialog.addDialogStatus = true
			},
			update(row){
				let id = row.Id ? row.Id : this.ids.join(',')
				getUpdateInfo({Id:id}).then(res => {
					if(res.status == 200){
						this.dialog.updateDialogStatus = true
						this.updateInfo = res.data
					}
				})
			},
			del(row){
				confirm({content:this.$t('system.confirmOperation')}).then(() => {
					let ids = row.cusBillNo ? row.cusBillNo : this.ids.join(',')
					del({cusBillNo:ids}).then(res => {
						this.$message({message: this.$t(res.msg), type: 'success'})
						this.index()
					})
				}).catch(() => {})
			},
      detail(row){
        this.detailInfo = {billNo:row.cusBillNo }
        console.log(this.detailInfo)
        this.dialog.detailDialogStatus = true
      },
			importData(){
				this.dialog.importDataDialogStatus = true
			},
      importUpdateData(){
        this.dialog.updateDataDialogStatus = true
      },
			selection(selection) {
			    this.selectRows=selection
			    this.selectTotal=selection.length
				this.ids = selection.map(item => item.id)
				this.single = selection.length != 1
				this.multiple = !selection.length
			},
			handleRowClick(row, rowIndex,event){
				if(event.target.className !== 'el-input__inner'){
					this.$refs.multipleTable.toggleRowSelection(row)
				}
			},
			rowClass ({ row, rowIndex }) {
				for(let i=0;i<this.ids.length;i++) {
					if (row.id === this.ids[i]) {
						return 'rowLight'
					}
				}
			},
		},	
		mounted(){
			this.index()
		}
	}
</script>
<style  lang="scss">
@import '@/assets/scss/common.scss';
</style>